// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_float_from_datetimev2_3_part3") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_float_from_datetimev2_3_part3_3_nullable;"
    sql "create table test_cast_to_float_from_datetimev2_3_part3_3_nullable(f1 int, f2 datetimev2(3)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_datetimev2_3_part3_3_nullable values (0, "0001-12-28 00:59:00.000"),(1, "0001-12-28 00:59:00.000"),(2, "0001-12-28 00:59:00.999"),(3, "0001-12-28 00:59:01.000"),(4, "0001-12-28 00:59:01.000"),(5, "0001-12-28 00:59:01.999"),(6, "0001-12-28 00:59:59.000"),(7, "0001-12-28 00:59:59.000"),(8, "0001-12-28 00:59:59.999"),(9, "0001-12-28 01:00:00.000"),(10, "0001-12-28 01:00:00.000"),(11, "0001-12-28 01:00:00.999"),(12, "0001-12-28 01:00:01.000"),(13, "0001-12-28 01:00:01.000"),(14, "0001-12-28 01:00:01.999"),(15, "0001-12-28 01:00:59.000"),(16, "0001-12-28 01:00:59.000"),(17, "0001-12-28 01:00:59.999"),(18, "0001-12-28 01:01:00.000"),(19, "0001-12-28 01:01:00.000"),
      (20, "0001-12-28 01:01:00.999"),(21, "0001-12-28 01:01:01.000"),(22, "0001-12-28 01:01:01.000"),(23, "0001-12-28 01:01:01.999"),(24, "0001-12-28 01:01:59.000"),(25, "0001-12-28 01:01:59.000"),(26, "0001-12-28 01:01:59.999"),(27, "0001-12-28 01:59:00.000"),(28, "0001-12-28 01:59:00.000"),(29, "0001-12-28 01:59:00.999"),(30, "0001-12-28 01:59:01.000"),(31, "0001-12-28 01:59:01.000"),(32, "0001-12-28 01:59:01.999"),(33, "0001-12-28 01:59:59.000"),(34, "0001-12-28 01:59:59.000"),(35, "0001-12-28 01:59:59.999"),(36, "0001-12-28 23:00:00.000"),(37, "0001-12-28 23:00:00.000"),(38, "0001-12-28 23:00:00.999"),(39, "0001-12-28 23:00:01.000"),
      (40, "0001-12-28 23:00:01.000"),(41, "0001-12-28 23:00:01.999"),(42, "0001-12-28 23:00:59.000"),(43, "0001-12-28 23:00:59.000"),(44, "0001-12-28 23:00:59.999"),(45, "0001-12-28 23:01:00.000"),(46, "0001-12-28 23:01:00.000"),(47, "0001-12-28 23:01:00.999"),(48, "0001-12-28 23:01:01.000"),(49, "0001-12-28 23:01:01.000"),(50, "0001-12-28 23:01:01.999"),(51, "0001-12-28 23:01:59.000"),(52, "0001-12-28 23:01:59.000"),(53, "0001-12-28 23:01:59.999"),(54, "0001-12-28 23:59:00.000"),(55, "0001-12-28 23:59:00.000"),(56, "0001-12-28 23:59:00.999"),(57, "0001-12-28 23:59:01.000"),(58, "0001-12-28 23:59:01.000"),(59, "0001-12-28 23:59:01.999"),
      (60, "0001-12-28 23:59:59.000"),(61, "0001-12-28 23:59:59.000"),(62, "0001-12-28 23:59:59.999"),(63, "0010-01-01 00:00:00.000"),(64, "0010-01-01 00:00:00.000"),(65, "0010-01-01 00:00:00.999"),(66, "0010-01-01 00:00:01.000"),(67, "0010-01-01 00:00:01.000"),(68, "0010-01-01 00:00:01.999"),(69, "0010-01-01 00:00:59.000"),(70, "0010-01-01 00:00:59.000"),(71, "0010-01-01 00:00:59.999"),(72, "0010-01-01 00:01:00.000"),(73, "0010-01-01 00:01:00.000"),(74, "0010-01-01 00:01:00.999"),(75, "0010-01-01 00:01:01.000"),(76, "0010-01-01 00:01:01.000"),(77, "0010-01-01 00:01:01.999"),(78, "0010-01-01 00:01:59.000"),(79, "0010-01-01 00:01:59.000"),
      (80, "0010-01-01 00:01:59.999"),(81, "0010-01-01 00:59:00.000"),(82, "0010-01-01 00:59:00.000"),(83, "0010-01-01 00:59:00.999"),(84, "0010-01-01 00:59:01.000"),(85, "0010-01-01 00:59:01.000"),(86, "0010-01-01 00:59:01.999"),(87, "0010-01-01 00:59:59.000"),(88, "0010-01-01 00:59:59.000"),(89, "0010-01-01 00:59:59.999"),(90, "0010-01-01 01:00:00.000"),(91, "0010-01-01 01:00:00.000"),(92, "0010-01-01 01:00:00.999"),(93, "0010-01-01 01:00:01.000"),(94, "0010-01-01 01:00:01.000"),(95, "0010-01-01 01:00:01.999"),(96, "0010-01-01 01:00:59.000"),(97, "0010-01-01 01:00:59.000"),(98, "0010-01-01 01:00:59.999"),(99, "0010-01-01 01:01:00.000"),
      (100, "0010-01-01 01:01:00.000"),(101, "0010-01-01 01:01:00.999"),(102, "0010-01-01 01:01:01.000"),(103, "0010-01-01 01:01:01.000"),(104, "0010-01-01 01:01:01.999"),(105, "0010-01-01 01:01:59.000"),(106, "0010-01-01 01:01:59.000"),(107, "0010-01-01 01:01:59.999"),(108, "0010-01-01 01:59:00.000"),(109, "0010-01-01 01:59:00.000"),(110, "0010-01-01 01:59:00.999"),(111, "0010-01-01 01:59:01.000"),(112, "0010-01-01 01:59:01.000"),(113, "0010-01-01 01:59:01.999"),(114, "0010-01-01 01:59:59.000"),(115, "0010-01-01 01:59:59.000"),(116, "0010-01-01 01:59:59.999"),(117, "0010-01-01 23:00:00.000"),(118, "0010-01-01 23:00:00.000"),(119, "0010-01-01 23:00:00.999"),
      (120, "0010-01-01 23:00:01.000"),(121, "0010-01-01 23:00:01.000"),(122, "0010-01-01 23:00:01.999"),(123, "0010-01-01 23:00:59.000"),(124, "0010-01-01 23:00:59.000"),(125, "0010-01-01 23:00:59.999"),(126, "0010-01-01 23:01:00.000"),(127, "0010-01-01 23:01:00.000"),(128, "0010-01-01 23:01:00.999"),(129, "0010-01-01 23:01:01.000"),(130, "0010-01-01 23:01:01.000"),(131, "0010-01-01 23:01:01.999"),(132, "0010-01-01 23:01:59.000"),(133, "0010-01-01 23:01:59.000"),(134, "0010-01-01 23:01:59.999"),(135, "0010-01-01 23:59:00.000"),(136, "0010-01-01 23:59:00.000"),(137, "0010-01-01 23:59:00.999"),(138, "0010-01-01 23:59:01.000"),(139, "0010-01-01 23:59:01.000"),
      (140, "0010-01-01 23:59:01.999"),(141, "0010-01-01 23:59:59.000"),(142, "0010-01-01 23:59:59.000"),(143, "0010-01-01 23:59:59.999"),(144, "0010-01-28 00:00:00.000"),(145, "0010-01-28 00:00:00.000"),(146, "0010-01-28 00:00:00.999"),(147, "0010-01-28 00:00:01.000"),(148, "0010-01-28 00:00:01.000"),(149, "0010-01-28 00:00:01.999"),(150, "0010-01-28 00:00:59.000"),(151, "0010-01-28 00:00:59.000"),(152, "0010-01-28 00:00:59.999"),(153, "0010-01-28 00:01:00.000"),(154, "0010-01-28 00:01:00.000"),(155, "0010-01-28 00:01:00.999"),(156, "0010-01-28 00:01:01.000"),(157, "0010-01-28 00:01:01.000"),(158, "0010-01-28 00:01:01.999"),(159, "0010-01-28 00:01:59.000"),
      (160, "0010-01-28 00:01:59.000"),(161, "0010-01-28 00:01:59.999"),(162, "0010-01-28 00:59:00.000"),(163, "0010-01-28 00:59:00.000"),(164, "0010-01-28 00:59:00.999"),(165, "0010-01-28 00:59:01.000"),(166, "0010-01-28 00:59:01.000"),(167, "0010-01-28 00:59:01.999"),(168, "0010-01-28 00:59:59.000"),(169, "0010-01-28 00:59:59.000"),(170, "0010-01-28 00:59:59.999"),(171, "0010-01-28 01:00:00.000"),(172, "0010-01-28 01:00:00.000"),(173, "0010-01-28 01:00:00.999"),(174, "0010-01-28 01:00:01.000"),(175, "0010-01-28 01:00:01.000"),(176, "0010-01-28 01:00:01.999"),(177, "0010-01-28 01:00:59.000"),(178, "0010-01-28 01:00:59.000"),(179, "0010-01-28 01:00:59.999"),
      (180, "0010-01-28 01:01:00.000"),(181, "0010-01-28 01:01:00.000"),(182, "0010-01-28 01:01:00.999"),(183, "0010-01-28 01:01:01.000"),(184, "0010-01-28 01:01:01.000"),(185, "0010-01-28 01:01:01.999"),(186, "0010-01-28 01:01:59.000"),(187, "0010-01-28 01:01:59.000"),(188, "0010-01-28 01:01:59.999"),(189, "0010-01-28 01:59:00.000"),(190, "0010-01-28 01:59:00.000"),(191, "0010-01-28 01:59:00.999"),(192, "0010-01-28 01:59:01.000"),(193, "0010-01-28 01:59:01.000"),(194, "0010-01-28 01:59:01.999")
      ,(195, null);
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_3_part3_3_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_3_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_3_part3_3_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_datetimev2_3_part3_3_not_nullable;"
    sql "create table test_cast_to_float_from_datetimev2_3_part3_3_not_nullable(f1 int, f2 datetimev2(3)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_datetimev2_3_part3_3_not_nullable values (0, "0001-12-28 00:59:00.000"),(1, "0001-12-28 00:59:00.000"),(2, "0001-12-28 00:59:00.999"),(3, "0001-12-28 00:59:01.000"),(4, "0001-12-28 00:59:01.000"),(5, "0001-12-28 00:59:01.999"),(6, "0001-12-28 00:59:59.000"),(7, "0001-12-28 00:59:59.000"),(8, "0001-12-28 00:59:59.999"),(9, "0001-12-28 01:00:00.000"),(10, "0001-12-28 01:00:00.000"),(11, "0001-12-28 01:00:00.999"),(12, "0001-12-28 01:00:01.000"),(13, "0001-12-28 01:00:01.000"),(14, "0001-12-28 01:00:01.999"),(15, "0001-12-28 01:00:59.000"),(16, "0001-12-28 01:00:59.000"),(17, "0001-12-28 01:00:59.999"),(18, "0001-12-28 01:01:00.000"),(19, "0001-12-28 01:01:00.000"),
      (20, "0001-12-28 01:01:00.999"),(21, "0001-12-28 01:01:01.000"),(22, "0001-12-28 01:01:01.000"),(23, "0001-12-28 01:01:01.999"),(24, "0001-12-28 01:01:59.000"),(25, "0001-12-28 01:01:59.000"),(26, "0001-12-28 01:01:59.999"),(27, "0001-12-28 01:59:00.000"),(28, "0001-12-28 01:59:00.000"),(29, "0001-12-28 01:59:00.999"),(30, "0001-12-28 01:59:01.000"),(31, "0001-12-28 01:59:01.000"),(32, "0001-12-28 01:59:01.999"),(33, "0001-12-28 01:59:59.000"),(34, "0001-12-28 01:59:59.000"),(35, "0001-12-28 01:59:59.999"),(36, "0001-12-28 23:00:00.000"),(37, "0001-12-28 23:00:00.000"),(38, "0001-12-28 23:00:00.999"),(39, "0001-12-28 23:00:01.000"),
      (40, "0001-12-28 23:00:01.000"),(41, "0001-12-28 23:00:01.999"),(42, "0001-12-28 23:00:59.000"),(43, "0001-12-28 23:00:59.000"),(44, "0001-12-28 23:00:59.999"),(45, "0001-12-28 23:01:00.000"),(46, "0001-12-28 23:01:00.000"),(47, "0001-12-28 23:01:00.999"),(48, "0001-12-28 23:01:01.000"),(49, "0001-12-28 23:01:01.000"),(50, "0001-12-28 23:01:01.999"),(51, "0001-12-28 23:01:59.000"),(52, "0001-12-28 23:01:59.000"),(53, "0001-12-28 23:01:59.999"),(54, "0001-12-28 23:59:00.000"),(55, "0001-12-28 23:59:00.000"),(56, "0001-12-28 23:59:00.999"),(57, "0001-12-28 23:59:01.000"),(58, "0001-12-28 23:59:01.000"),(59, "0001-12-28 23:59:01.999"),
      (60, "0001-12-28 23:59:59.000"),(61, "0001-12-28 23:59:59.000"),(62, "0001-12-28 23:59:59.999"),(63, "0010-01-01 00:00:00.000"),(64, "0010-01-01 00:00:00.000"),(65, "0010-01-01 00:00:00.999"),(66, "0010-01-01 00:00:01.000"),(67, "0010-01-01 00:00:01.000"),(68, "0010-01-01 00:00:01.999"),(69, "0010-01-01 00:00:59.000"),(70, "0010-01-01 00:00:59.000"),(71, "0010-01-01 00:00:59.999"),(72, "0010-01-01 00:01:00.000"),(73, "0010-01-01 00:01:00.000"),(74, "0010-01-01 00:01:00.999"),(75, "0010-01-01 00:01:01.000"),(76, "0010-01-01 00:01:01.000"),(77, "0010-01-01 00:01:01.999"),(78, "0010-01-01 00:01:59.000"),(79, "0010-01-01 00:01:59.000"),
      (80, "0010-01-01 00:01:59.999"),(81, "0010-01-01 00:59:00.000"),(82, "0010-01-01 00:59:00.000"),(83, "0010-01-01 00:59:00.999"),(84, "0010-01-01 00:59:01.000"),(85, "0010-01-01 00:59:01.000"),(86, "0010-01-01 00:59:01.999"),(87, "0010-01-01 00:59:59.000"),(88, "0010-01-01 00:59:59.000"),(89, "0010-01-01 00:59:59.999"),(90, "0010-01-01 01:00:00.000"),(91, "0010-01-01 01:00:00.000"),(92, "0010-01-01 01:00:00.999"),(93, "0010-01-01 01:00:01.000"),(94, "0010-01-01 01:00:01.000"),(95, "0010-01-01 01:00:01.999"),(96, "0010-01-01 01:00:59.000"),(97, "0010-01-01 01:00:59.000"),(98, "0010-01-01 01:00:59.999"),(99, "0010-01-01 01:01:00.000"),
      (100, "0010-01-01 01:01:00.000"),(101, "0010-01-01 01:01:00.999"),(102, "0010-01-01 01:01:01.000"),(103, "0010-01-01 01:01:01.000"),(104, "0010-01-01 01:01:01.999"),(105, "0010-01-01 01:01:59.000"),(106, "0010-01-01 01:01:59.000"),(107, "0010-01-01 01:01:59.999"),(108, "0010-01-01 01:59:00.000"),(109, "0010-01-01 01:59:00.000"),(110, "0010-01-01 01:59:00.999"),(111, "0010-01-01 01:59:01.000"),(112, "0010-01-01 01:59:01.000"),(113, "0010-01-01 01:59:01.999"),(114, "0010-01-01 01:59:59.000"),(115, "0010-01-01 01:59:59.000"),(116, "0010-01-01 01:59:59.999"),(117, "0010-01-01 23:00:00.000"),(118, "0010-01-01 23:00:00.000"),(119, "0010-01-01 23:00:00.999"),
      (120, "0010-01-01 23:00:01.000"),(121, "0010-01-01 23:00:01.000"),(122, "0010-01-01 23:00:01.999"),(123, "0010-01-01 23:00:59.000"),(124, "0010-01-01 23:00:59.000"),(125, "0010-01-01 23:00:59.999"),(126, "0010-01-01 23:01:00.000"),(127, "0010-01-01 23:01:00.000"),(128, "0010-01-01 23:01:00.999"),(129, "0010-01-01 23:01:01.000"),(130, "0010-01-01 23:01:01.000"),(131, "0010-01-01 23:01:01.999"),(132, "0010-01-01 23:01:59.000"),(133, "0010-01-01 23:01:59.000"),(134, "0010-01-01 23:01:59.999"),(135, "0010-01-01 23:59:00.000"),(136, "0010-01-01 23:59:00.000"),(137, "0010-01-01 23:59:00.999"),(138, "0010-01-01 23:59:01.000"),(139, "0010-01-01 23:59:01.000"),
      (140, "0010-01-01 23:59:01.999"),(141, "0010-01-01 23:59:59.000"),(142, "0010-01-01 23:59:59.000"),(143, "0010-01-01 23:59:59.999"),(144, "0010-01-28 00:00:00.000"),(145, "0010-01-28 00:00:00.000"),(146, "0010-01-28 00:00:00.999"),(147, "0010-01-28 00:00:01.000"),(148, "0010-01-28 00:00:01.000"),(149, "0010-01-28 00:00:01.999"),(150, "0010-01-28 00:00:59.000"),(151, "0010-01-28 00:00:59.000"),(152, "0010-01-28 00:00:59.999"),(153, "0010-01-28 00:01:00.000"),(154, "0010-01-28 00:01:00.000"),(155, "0010-01-28 00:01:00.999"),(156, "0010-01-28 00:01:01.000"),(157, "0010-01-28 00:01:01.000"),(158, "0010-01-28 00:01:01.999"),(159, "0010-01-28 00:01:59.000"),
      (160, "0010-01-28 00:01:59.000"),(161, "0010-01-28 00:01:59.999"),(162, "0010-01-28 00:59:00.000"),(163, "0010-01-28 00:59:00.000"),(164, "0010-01-28 00:59:00.999"),(165, "0010-01-28 00:59:01.000"),(166, "0010-01-28 00:59:01.000"),(167, "0010-01-28 00:59:01.999"),(168, "0010-01-28 00:59:59.000"),(169, "0010-01-28 00:59:59.000"),(170, "0010-01-28 00:59:59.999"),(171, "0010-01-28 01:00:00.000"),(172, "0010-01-28 01:00:00.000"),(173, "0010-01-28 01:00:00.999"),(174, "0010-01-28 01:00:01.000"),(175, "0010-01-28 01:00:01.000"),(176, "0010-01-28 01:00:01.999"),(177, "0010-01-28 01:00:59.000"),(178, "0010-01-28 01:00:59.000"),(179, "0010-01-28 01:00:59.999"),
      (180, "0010-01-28 01:01:00.000"),(181, "0010-01-28 01:01:00.000"),(182, "0010-01-28 01:01:00.999"),(183, "0010-01-28 01:01:01.000"),(184, "0010-01-28 01:01:01.000"),(185, "0010-01-28 01:01:01.999"),(186, "0010-01-28 01:01:59.000"),(187, "0010-01-28 01:01:59.000"),(188, "0010-01-28 01:01:59.999"),(189, "0010-01-28 01:59:00.000"),(190, "0010-01-28 01:59:00.000"),(191, "0010-01-28 01:59:00.999"),(192, "0010-01-28 01:59:01.000"),(193, "0010-01-28 01:59:01.000"),(194, "0010-01-28 01:59:01.999");
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_3_part3_3_not_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_3_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_3_part3_3_not_nullable order by 1;'

}